package com.tc168.cp306.b06.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.tc168.cp306.b06.MyApplication;
import com.tc168.cp306.b06.R;
import com.tc168.cp306.b06.bean.Topticbean;
import com.tc168.cp306.b06.gen.TopticbeanDao;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class addActivity extends AppCompatActivity {

    @BindView(R.id.tilte)
    EditText tilte;
    @BindView(R.id.counet)
    EditText counet;
    @BindView(R.id.tpynum)
    EditText tpynum;
    @BindView(R.id.isbuuton)
    Button isbuuton;
    @BindView(R.id.qingchu)
    Button qingchu;
    @BindView(R.id.istrue)
    Button istrue;

    private TopticbeanDao topticbeanDao;

    private Boolean ss = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        ButterKnife.bind(this);
        topticbeanDao = MyApplication.getmDaoSession().getTopticbeanDao();

        qingchu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tilte.setText("");
                counet.setText("");
            }
        });
        istrue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ss = !ss;

                istrue.setText(""+ss);
            }
        });

    }

    @OnClick(R.id.isbuuton)
    public void onViewClicked() {


        String s = tpynum.getText().toString();
        int num = Integer.parseInt(s);
        Topticbean personbeanadd = new Topticbean(null, tilte.getText().toString(), counet.getText().toString(), num, ss);
        topticbeanDao.insert(personbeanadd);

        Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show();
    }


}
